package me.leiusual.sharing.ui.shop

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations.switchMap
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.api.model.BusinessLevel
import me.leiusual.sharing.repository.BusinessRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * author: leiusual
 * create on: 2019-08-02
 * description:
 */
class ShopBusinessLevelViewModel @Inject constructor(
    private val businessRepository: BusinessRepository
) : ViewModel() {

  // 业务级别

  private val _businessLevel = MutableLiveData<String>()
  val businessLevel: LiveData<Data<List<BusinessLevel>>> = switchMap(_businessLevel) {
    businessRepository.businessApply(it).toLiveData()
  }

  fun businessLevel(type: String) {
    _businessLevel.value = type
  }
}